package com.thrc.borrow.utils;

import java.util.Random;

import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.util.StringUtils;

/**
 * 密码相关，包括编码，生成hash
 * 
 * @author Administrator
 *
 */
public class SecretUtil {

	/**
	 * 生成 4位 hash值
	 * 
	 * @return
	 */
	public static String getHash() {

		return String.valueOf(new Random().nextInt(8999) + 1000);
	}

	/**
	 * 根据传入pwd和私有hash（盐） 生成PWD
	 * 
	 * @return
	 */
	public static String getMd5Pwd(String rawPass, Object salt) {

		if (StringUtils.isEmpty(rawPass) || salt == null)
			return null;

		return new Md5PasswordEncoder().encodePassword(rawPass, salt);
	}

}
